package com.april.pattern.structural.proxy;

import com.april.pattern.structural.proxy.dynamicproxy.OrderServiceDynamicProxy;
import com.april.pattern.structural.proxy.staticproxy.OrderServiceStaticProxy;
import org.junit.jupiter.api.Test;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/07/06 16:36
 * @description
 */
public class ProxyTest {
    /**
     * 测试静态代理
     */
    @Test
    public void staticProxy() {
        Order order = new Order();
        order.setUserId(2);

        OrderServiceStaticProxy orderServiceStaticProxy = new OrderServiceStaticProxy();
        orderServiceStaticProxy.saveOrder(order);
    }

    /**
     * 测试动态代理
     */
   @Test
   public void dynamicProxy() {
        Order order = new Order();
        order.setUserId(2);

       OrderService orderServiceDynamicProxy =
               (OrderService) new OrderServiceDynamicProxy(new OrderServiceImpl()).bind();
       orderServiceDynamicProxy.saveOrder(order);
   }
}
